import time
from time import sleep
from selenium.webdriver.common.by import By
from base.base_page import BasePage

class UserLoginPage(BasePage):
    # username_input = (By.XPATH, '//input[@placeholder="请输入账号"]')
    username_input = (By.CSS_SELECTOR, 'input[type="text"].el-input__inner')
    pwd_input =(By.CSS_SELECTOR, 'input[type="password"].el-input__inner')
    login_btn =(By.CSS_SELECTOR, 'button[data-v-0144f9b4].ubtn-red')
    logout_btn =(By.XPATH, '//a[text()="注销登录"]')
    error_message_username = (By.XPATH, '//html/body/div/div[2]/div/form/div[1]/div/div[2]')
    error_message_pwd = (By.XPATH, '//div[@class="el-form-item__error"]')
    error_message_popup = (By.XPATH, '//p[@class="el-message__content"]')

    def username(self,username):#  输入用户名
        self.input_element(self.username_input,username,page_name=f'账号输入')
    def pwd(self,pwd):# 输入密码
        self.input_element(self.pwd_input,pwd,page_name=f'密码输入')

    def username_pwd(self,username,pwd):
        self.input_element(self.username_input,username,page_name=f'账号输入')
        self.input_element(self.pwd_input,pwd,page_name=f'密码输入')
        self.click(self.login_btn, page_name='点击登录')
    def click_login(self):# 点击登录
        self.click(self.login_btn,page_name='点击登录')
        sleep(2)

    def username_error_message(self):# 获取用户名错误信息
        return self.get_text(self.error_message_username,page_name='获取用户名错误提示信息')

    def pwd_error_message(self):# 获取密码错误信息
        return self.get_text(self.error_message_pwd,page_name='获取密码错误提示信息')

    def popup_error_message(self):# 获取popup错误信息
        return self.get_text(self.error_message_popup,page_name='获取登录错误提示信息')


    def panduan(self):
        if self.visibility_element(self.error_message_popup):
            return self.get_text(self.error_message_popup,page_name='获取登录错误文本信息')
        if self.visibility_element(self.error_message_username):
           return self.get_text(self.error_message_username,page_name='获取用户名错误信息')
        elif self.visibility_element(self.error_message_pwd):
            return self.get_text(self.error_message_pwd,page_name='获取密码错误文本信息')
        else:
            return '登录成功'


    # def case_dame(self):
    #     return self.get_text(self.error_message_popup,page_name='错误信息')








